<template>
  <section class="main">
    <div class="bg">
      <div class="head">
        <div class="topSearch">
          <div class="search-box">
            <a class="city-sel"
               href="javascript:void(0);">
              <span>广州市区</span>
            </a>
            <a href="#/search"
               class="goToSearch">
              <van-icon name="search"
                        size="0.32rem"
                        color="#9c9c9c" />
              <span>5G手机</span>
            </a>
          </div>
        </div>
        <nav class="slide-tabs">
          <a href="javascript:void(0);"
             v-for="(item,index) in navlist"
             :key="index"
             v-text="item"
             :class="{cur:num==index}"
             @click="change(index)"></a>
        </nav>
      </div>
    </div>
    <lbt />
    <div class="floorPicture">
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1377/c12348e35e3868.png.webp"
             alt />
      </a>
    </div>
    <div class="floor-picture">
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1380/01565b58a95490ed.jpg.webp"
             alt />
      </a>
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1379/01565b6718bd72b8.jpg.webp"
             alt />
      </a>
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1378/01565b73f4be7ac5.jpg.webp"
             alt />
      </a>
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1383/01565b779a9b275b.jpg.webp"
             alt />
      </a>
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1379/01565b7fe93b1031.jpg.webp"
             alt />
      </a>
    </div>
    <div class="fast">
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1377/fd37bb381d389c.png.webp"
             alt />
        <img src="https://img2.ch999img.com/newstatic/1383/fd37dbef9d3302.png.webp"
             alt />
      </a>
    </div>
    <div class="space"></div>
    <div class="flPice">
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1378/0157451aa84b24c7.jpg.webp"
             alt />
        <img src="https://img2.ch999img.com/newstatic/1377/0157450a5875ead8.jpg.webp"
             alt />
      </a>
    </div>
    <div class="gift">
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1378/0150ff624fc1a418.jpg.webp"
             alt />
      </a>
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/1383/0150ff6dc7c7a51b.jpg.webp"
             alt />
      </a>
    </div>
    <div class="floor">
      <a href="javascript:void(0);">
        <img src="https://img2.ch999img.com/newstatic/769/2f9b9cb8e1a5d2.png.webp"
             alt />
      </a>
    </div>
    <div class="productList">
      <a href="#/goods"
         v-for="(item,index) in homelist"
         :key="index">
        <img :src="item.imagePath"
             alt />
        <p class="pdttitle"
           v-text="item.sellingPoint"></p>
        <p class="pdtname"
           v-text="item.title"></p>
        <p class="pdtprice">￥{{item.price}}</p>
      </a>
    </div>
    <div class="loginNow"
         v-show="this.$store.state.logintype==false">
      <div class="loginTips">
        <p>登录尊享极致购物体验</p>
        <a href="#/login">立即登录</a>
      </div>
    </div>
    <a href="javascript:"
       class="toTop"></a>
  </section>
</template>
<script>
import lbt from "../components/lbt";
import { homedata } from "../data/homedata.js";
import $ from "../../node_modules/jquery/dist/jquery";
export default {
  data () {
    return {
      navlist: [
        "推荐",
        "限时购",
        "拼团购",
        "砍价",
        "购旧机",
        "回收手机",
        "快修",
        "头条"
      ],
      num: 0,
      homelist: []
    };
  },
  methods: {
    change (index) {
      this.num = index;
    }
  },
  components: {
    lbt
  },

  mounted () {
    if (localStorage.checked) {
      let token;
      if (localStorage.checked == "false") {
        token = sessionStorage.token;
      } else {
        token = localStorage.token;
      }
      if (token != undefined) {
        $.ajax({
          type: "get",
          url: "/user/checktoken",
          data: { token },
          dataType: "json",
          success: response => {
            if (response.msg == "已登录") {
              this.$store.state.logintype = true;
            }
          }
        });
      }
    }
    this.homelist = homedata;
    $(".toTop").click(() => {
      $(".main")
        .stop()
        .animate(
          {
            scrollTop: 0
          },
          500
        );
    });

    $(".main").scroll(() => {
      if ($(".main").scrollTop() > 100) {
        $(".toTop").show();
        $(".loginNow")
          .stop()
          .animate(
            {
              width: "5rem"
            },
            50
          );
      }
      if ($(".main").scrollTop() <= 100) {
        $(".toTop").hide();
        $(".loginNow")
          .stop()
          .animate(
            {
              width: "6.86rem"
            },
            50
          );
      }
    });
  }
};
</script>
<style scoped>
.bg {
  overflow: hidden;
  width: 100vw;
  height: 4.13rem;
  background-image: url(../images/bg.png);
  background-size: 100% auto;
  background-repeat: no-repeat;
  background-color: #e31313;
}
.head {
  z-index: 10;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  background-image: url(../images/bg.png);
  background-size: 100%;
  background-repeat: no-repeat;
  background-color: #e31313;
}
.topSearch {
  margin-top: 0.28rem;
  width: 100vw;
  height: 0.88rem;
}
.search-box {
  background: #fff;
  border-radius: 30px;
  height: 0.68rem;
  padding: 0 15px;
  margin: 14px;
  display: flex;
  align-items: center;
}
.city-sel {
  padding-right: 10px;
  justify-content: center;
  align-items: center;
  display: block;
}
.city-sel span {
  display: block;
  text-overflow: ellipsis;
  overflow: hidden;
  -webkit-box-orient: vertical;
  line-height: 1.2;
  word-break: break-all;
  font-size: 0.28rem;
  color: #333333;
}
.goToSearch {
  display: block;
  width: 4.62rem;
  height: 100%;
  padding: 0 10px;
}
.goToSearch i {
  font-weight: bold;
  float: left;
  height: 100%;
  line-height: 0.68rem;
  text-align: center;
  margin: 0 4px;
}
.goToSearch span {
  display: block;
  height: 100%;
  float: left;
  color: #9c9c9c;
  font-size: 0.28rem;
  line-height: 0.64rem;
}
.slide-tabs {
  width: 100vw;
  height: 0.8rem;
  overflow-x: scroll;
  overflow-y: hidden;
  display: flex;
}
.slide-tabs a {
  margin: 0 10px;
  height: 0.8rem;
  line-height: 0.8rem;
  font-size: 0.3rem;
  word-break: break-all;
  color: #ffffff;
  flex-shrink: 0;
  opacity: 0.8;
}
.slide-tabs .cur {
  font-size: 0.32rem;
  opacity: 1;
}
.floorPicture {
  width: 100vw;
  height: 0.48rem;
}
.floorPicture a {
  display: block;
  width: 100%;
  height: 100%;
}
.floorPicture img {
  display: block;
  width: 100%;
  height: 100%;
}
.floor-picture {
  width: 100vw;
  height: 1.5rem;
  display: flex;
}
.floor-picture a {
  display: block;
  flex: 1;
}
.floor-picture img {
  display: block;
  width: 100%;
  height: 100%;
}
.fast {
  width: 100vw;
  height: 1.25rem;
  background-color: #f5f5f5;
}
.fast a {
  display: block;
  width: 100%;
  height: 100%;
}
.fast a img {
  float: left;
  display: block;
  width: 50%;
  height: 100%;
}
.space {
  height: 0.1rem;
  width: 100vw;
  background-color: #f5f5f5;
}
.flPice {
  width: 100vw;
  height: 2.5rem;
}
.flPice a {
  display: block;
  width: 100%;
  height: 100%;
}
.flPice a img {
  float: left;
  display: block;
  width: 50%;
  height: 100%;
}
.gift {
  width: 100vw;
  height: 2.5rem;
}
.gift a {
  float: left;
  display: block;
  width: 50%;
  height: 100%;
}
.gift a img {
  float: left;
  display: block;
  width: 100%;
  height: 100%;
}
.toTop {
  display: block;
  width: 40px;
  height: 40px;
  background-image: url("../images/back-top.png");
  background-size: 100% 100%;
  position: fixed;
  right: 16px;
  bottom: 68px;
  display: none;
}
.loginNow {
  position: fixed;
  height: 44px;
  left: 16px;
  right: 16px;
  bottom: 66px;
  margin: 0 auto;
  max-width: 640px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}
.loginTips {
  width: 6.86rem;
  border-radius: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 0 16px;
  font-size: 0.37rem;
  transition: all 0.3s ease;
  pointer-events: auto;
  flex-grow: 1;
  align-items: center;
  justify-content: space-between;
  display: flex;
}
.loginTips p {
  font-size: 14px;
}
.loginTips a {
  width: 70px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  background-color: #f21c1c;
  border-radius: 24px;
  font-size: 12px;
  color: #ffffff;
}
.floor-tops {
  height: 44px;
  margin: 0.4rem;
  background: #fff;
  border-radius: 44px;
  box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.08);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.LeftImg {
  width: 68px;
  padding: 0 12px;
  display: block;
}
.floor {
  background: #fff;
  width: 100vw;
  height: 1.17333rem;
}
.floor a {
  display: block;
  width: 100%;
  height: 100%;
}
.floor a img {
  display: block;
  width: 100%;
  height: 100%;
}
.productList {
  width: 100vw;
  /* padding: 0 14px; */
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}
.productList a {
  width: 3.375rem;
  background: #fff;
  margin-top: 0.2rem;
  padding-bottom: 10px;
  position: relative;
  box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.08);
  border-radius: 3px;
}
.productList img {
  width: 3rem;
  height: 3rem;
  display: block;
  margin: 10px auto;
}
.productList .pdttitle {
  background: #ebf6fe;
  color: #87acd8;
  padding: 5px 15px;
  font-size: 0.26rem;
}
.pdtname {
  width: 2.775rem;
  height: 0.32rem;
  margin: 5px 15px;
  font-size: 0.26rem;
  color: #333333;
  text-overflow: ellipsis;
  overflow: hidden;
  -webkit-box-orient: vertical;
  line-height: 1.2;
  word-break: break-all;
  white-space: nowrap;
}
.pdtprice {
  margin: 5px 15px 0;
  font-size: 15px;
  color: #f21c1c;
}
</style>